using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using EPiAbstractions;
using EPiServer.Core;
using JoelAbrahamsson.FeedImport;
using JoelAbrahamsson.PageTypes;

namespace JoelAbrahamsson.Web.Controllers
{
    public class DeliciousFeedController : Controller
    {
        private IDataFactoryFacade _dataFactoryFacade;

        public DeliciousFeedController(IDataFactoryFacade dataFactoryFacade)
        {
            _dataFactoryFacade = dataFactoryFacade;
        }

        public ActionResult Index(int? twitterItemsCount)
        {            
            Start startPage = (Start) _dataFactoryFacade.GetPage(PageReference.StartPage);
            if (startPage.DeliciousFeedRoot == null)
                return View(new List<SyndicationFeedItem>());
            //RelatedPageSearch search = new RelatedPageSearch();
            //search.Test();
            IEnumerable<SyndicationFeedItem> items = _dataFactoryFacade.GetChildren(startPage.DeliciousFeedRoot.PageLink).Cast<SyndicationFeedItem>();

            return View(items);
        }
    }
}
